package net.wanho.controller;

import net.wanho.entity.User;
import net.wanho.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * Author：汤小洋
 * Date：2025-10-27 10:53
 * Description：<描述>
 */
@RestController
@RequestMapping("/users")
@RefreshScope // nacos配置自动刷新
public class UserController {

    @Value("${server.port}")
    private int port;

    @Value("${spring.datasource.url}")
    private String url;

    @Value("${shop.share.name}")
    private String name;

    @GetMapping("/test")
    public String test(){
        return "provider：" + port + "-------->" + url + "----------->" + name;
    }

    @GetMapping
    public AjaxResult list(String username){
        User user = new User(1, username, "123456");
        return AjaxResult.success(user);
    }

    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable Integer id){
        return AjaxResult.success("删除成功：" + id);
    }

    @PostMapping
    public AjaxResult add(@RequestBody User user){
        return AjaxResult.success(user);
    }
}
